
let arr=[]
let ul=document.querySelector('ul')
let xhr =new XMLHttpRequest()
xhr.open('get','http://chst.vip:1234/api/getcategorytitle',false)
xhr.onload=function(){
    if(xhr.status===200){
        let res =JSON.parse(xhr.responseText)
        let an=res .result
        console.log(an);
        let lis=''
        an.forEach(item => {
            lis+=`
            <li>
                <h4>${item.title}</h4>
                <i class="iconfont icon-xiajiantou"></i>
                <div class="down">
                </div>
            </li>
            ` 
            arr.push(item.titleId)
        });
        ul.innerHTML=lis
    }
}
xhr.send(null)

let down=document.querySelectorAll('.classification .down')
arr.forEach((a,b)=>{
    let xhr1=new XMLHttpRequest()
    xhr1.open('get',`http://chst.vip:1234/api/getcategory?titleid=${a}`,false)
    xhr1.onload=function(){
        if(xhr1.status===200){
            let res1=JSON.parse(xhr1.responseText)
            let las=''
            console.log(res1);
            res1.result.forEach(c=>{
                las+=`<p categoryId=${c.categoryId}>${c.category}</p>`
            })
            down[b].innerHTML=las
        }
    }
    xhr1.send(null)  
})

$('.down').slideUp(0)
$('.classification li').click(function(){
    $(this).find('.down').slideToggle().parent().siblings().find('.down').slideUp()
})






ul.onclick=function(e){
    var e=e || window.event
    var target=e.target || e.srcElement
    if(target.nodeName==='P'){
        console.log(target.getAttribute('categoryId'));
        localStorage.setItem('categoryId',target.getAttribute('categoryId'))
        location.href = 'http://127.0.0.1:5500/js/day18/html/paging.html';
    }
}
